
(function () {
  'use strict';

  angular.module('KingAdmin.pages.common')
      .factory('CommonService', CommonService);

  /** @ngInject */
  function CommonService($uibModal) {
      function show(page, size,controller,items,callbackFunc) {
          $uibModal.open({
              animation: true,
              templateUrl: page,
              controller : controller || 'CommomCtrl',
              size: size || 'sm',
              resolve: {
                  items: function () {
                      return items;
                  }
              }
          }).result.then(function(opParams){
              return callbackFunc(opParams);
          });
      };
      function common(items,callbackFunc,page){
          show(page, 'sm','CommomCtrl',items,callbackFunc)
      }
      function info(items,callbackFunc){
          common(items,callbackFunc,'app/pages/common/modalTemplates/infoModal.html')
      };
      function success(items,callbackFunc){
          common(items,callbackFunc,'app/pages/common/modalTemplates/successModal.html')
      };
      function warning(items,callbackFunc){
          common(items,callbackFunc,'app/pages/common/modalTemplates/warningModal.html')
      };
      function danger(items,callbackFunc){
          common(items,callbackFunc,'app/pages/common/modalTemplates/dangerModal.html')
      };

      function showImg(imgSrc, title) {
          $uibModal.open({
              templateUrl: 'app/pages/common/imgView/imgView.html',
              controllerAs: 'kt',
              backdrop: 'static',
              size: 'lg',
              controller: function ($scope, imgSrc, title) {
                  $scope.imgSrc = imgSrc;
                  $scope.title = title;
                  // $scope.imgSrc = 'http://127.0.0.1:7080/devimg/0f0e0d000001/18-09-10_10_54_767.jpg';
              },
              resolve: {
                  imgSrc: function () {
                      return imgSrc;
                  },
                  title: function () {
                      return title;
                  }
              }
          })
      }

      function showHkVideo(cameraId) {
          $uibModal.open({
              templateUrl: 'app/pages/common/hikVideo/hkVideo.html',
              controllerAs: 'kt',
              backdrop: 'static',
              size: 'lg',
              controller: 'VideoCtrl',
              resolve: {
                  cameraId: function () {
                      return cameraId;
                  }
              }
          })
      }

      function showEvCharts(channelId) {
          $uibModal.open({
              templateUrl: 'app/pages/common/charts/chartsModal.html',
              controllerAs: 'kt',
              backdrop: 'static',
              size: 'lg',
              controller: function($scope, channelId) {
                  $scope.chnId = channelId;
                  console.log($scope.chnId);
              },
              resolve: {
                  channelId: function () {
                      return channelId;
                  }
              }
          })
      }

      return{
          show:show,
          info:info,
          success:success,
          warning:warning,
          danger:danger,
          showImg: showImg,
          showHkVideo: showHkVideo,
          showEvCharts: showEvCharts,
      }
  }

})();
